export default {
  // [types.SET_ARTICLEACTIONLIST] (state, data) {
  //   state.articleActionList = data
  // },
  setArticleActionList (state, List) {
    state.articleActionList = List
  },
  // *******************文章关注、点赞(喜欢)、不喜欢、收藏、转发、阅读位置、配置 列表操作区*******************
  addArticleActionListFabulousCount (state, articleId) {
    // for (let i = 0; i < state.articleActionList.length; i++) {
    //   if (state.articleActionList[i].article_id === articleId) {
    //     state.articleActionList[i].fabulous_count++
    //     console.log(state.articleActionList[i].article_id)
    //   }
    // }
    state.articleActionList.forEach(item => {
      console.log(articleId)
      if (item.id === articleId) {
        item.fabulous_count++
        console.log(item.id)
      }
    })
  },
  addArticleActionListViewCount (state, articleId) {
    state.articleActionList.forEach(item => {
      if (item.id === articleId) {
        item.view_count++
      }
    })
  },
  addArticleActionListCommentCount (state, articleId) {
    state.articleActionList.forEach(item => {
      if (item.id === articleId) {
        item.comment_count++
      }
    })
  },
  addArticleActionListCollectionCount (state, articleId) {
    state.articleActionList.forEach(item => {
      if (item.id === articleId) {
        item.collection_count++
      }
    })
  },
  subArticleActionListFabulousCount (state, articleId) {
    state.articleActionList.forEach(item => {
      console.log(articleId)
      if (item.id === articleId) {
        item.fabulous_count--
        console.log(item.fabulous_count)
      }
    })
  },
  subArticleActionListViewCount (state, articleId) {
    state.articleActionList.view_count--
    state.articleActionList.forEach(item => {
      if (item.id === articleId) {
        item.view_count--
      }
    })
  },
  subArticleActionListCommentCount (state, articleId) {
    state.articleActionList.forEach(item => {
      if (item.id === articleId) {
        item.comment_count--
      }
    })
  },
  subArticleActionListCollectionCount (state, articleId) {
    state.articleActionList.forEach(item => {
      if (item.id === articleId) {
        item.collection_count--
      }
    })
  },
  reverseArticleActionListConfigFabulousCount (state, articleId) {
    state.articleActionList.forEach(item => {
      console.log(articleId)
      if (item.id === articleId) {
        item.isLike = !item.isLike
        console.log(item.isFabulous)
      }
    })
  },
  // 无
  reverseArticleActionListConfigViewCount (state, articleId) {
    state.articleActionList.forEach(item => {
      if (item.id === articleId) {
        item.isView = !item.isView
      }
    })
  },
  // 无
  reverseArticleActionListConfigCommentCount (state, articleId) {
    state.articleActionList.forEach(item => {
      if (item.id === articleId) {
        item.isComment = !item.isComment
      }
    })
  },
  reverseArticleActionListConfigCollectionCount (state, articleId) {
    state.articleActionList.forEach(item => {
      if (item.id === articleId) {
        item.isCollection = !item.isCollection
      }
    })
  },
  // *******************文章关注、点赞(喜欢)、不喜欢、收藏、转发、阅读位置、配置 单文章操作区*******************
  subArticleActionAndConfigFabulousCount (state, articleId) {
    if (state.articleActionAndConfig.article_id === articleId) {
      state.articleActionAndConfig.fabulous_count--
    }
  },
  subArticleActionAndConfigCollectionCount (state, articleId) {
    if (state.articleActionAndConfig.article_id === articleId) {
      state.articleActionAndConfig.collection_count--
    }
  },
  addArticleActionAndConfigFabulousCount (state, articleId) {
    if (state.articleActionAndConfig.article_id === articleId) {
      state.articleActionAndConfig.fabulous_count++
    }
  },
  addArticleActionAndConfigCollectionCount (state, articleId) {
    if (state.articleActionAndConfig.article_id === articleId) {
      state.articleActionAndConfig.collection_count++
    }
  },
  reverseArticleActionAndConfigFabulousCount (state, articleId) {
    if (state.articleActionAndConfig.article_id === articleId) {
      state.articleActionAndConfig.is_like = !state.articleActionAndConfig.is_like
    }
  },
  reverseArticleActionAndConfigCollectionCount (state, articleId) {
    if (state.articleActionAndConfig.article_id === articleId) {
      state.articleActionAndConfig.is_collection = !state.articleActionAndConfig.is_collection
    }
  },
  // *******************初始化操作区*******************
  // 列表数据转换成View需要的Model对象
  InitArticleList (state, data) {
    // console.log(data)
    if (data.length <= 0) {
      return this.$message.error('数据不存在！')
    }
    data.forEach((item) => {
      // 将字符串类型的数据转换成数组形如: "abc def" -> [abc,def]
      if (item.content.custom_tag) {
        item.content.custom_tag = item.content.custom_tag.split(' ')
      } else {
        item.content.custom_tag = null
      }
      item.content.image = item.content.image.split(' ')
      // 取出id和articleAction
      var object = item.article_opeartor
      var object2 = item.article_operator_config
      object.id = item.content.article_id
      // 合并两个对象
      const returnedTarget = Object.assign(object, object2)
      // console.log(returnedTarget)
      state.articleActionList.push(returnedTarget)
      state.articleList.push(item)
    })
  },
  // *******************单文章配置区*******************
  setArticleContent (state, content) {
    state.articleContent = content
  },
  setArticleActionAndConfig (state, content) {
    state.articleActionAndConfig = content
    // console.log(state.articleActionAndConfig)
  },
  // 清空文章列表数组
  clearArticleList (state) {
    state.articleList = []
  }
}
